package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    /*
    * 新增套餐
    * */
    @PostMapping
    public Result saveSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.saveSetmeal(setmealDTO);
        return Result.success();

    }

    /*
    * 根据ID批量删除套餐
    * */
    @DeleteMapping
    public Result deleteSetmeal(@RequestParam("ids")List<Integer> ids){
        setmealService.deleteSetmeal(ids);
        return Result.success();

    }

    /*
    * 修改套餐
    * */
    @PutMapping
    public Result putSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.putSetmeal(setmealDTO);
        return Result.success();
    }
    /*
    * 套餐分页查询
    * */
    @GetMapping("/page")
    public Result pageSetmeal(SetmealPageQueryDTO setmealPageQueryDTO){
       PageResult pageResult= setmealService.pageSetmeal(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /*
    * 停售 0
    * 启售 1
    * */
    @PostMapping("/status/{status}")
    public Result setmealStatus(@PathVariable Integer status,Integer id){
        setmealService.setmealStatus(status,id);
        return Result.success();
    }

    /*
    * 根据路径ID查询
    * */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id){
      SetmealDTO setmealDTO=  setmealService.selectById(id);
        return Result.success(setmealDTO);
    }
}
